package com.cskaoyan.market.service.impl;

import com.cskaoyan.market.service.GeneralIssueService;
import com.cskaoyan.market.db.domain.MarketIssue;
import com.cskaoyan.market.db.domain.MarketIssueExample;
import com.cskaoyan.market.db.mapper.MarketIssueMapper;
import com.cskaoyan.market.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @author TangHonghao
 * @since 2023/03/22 14:21
 */
public class GeneralIssueServiceImpl implements GeneralIssueService {
    @Override
    public List<MarketIssue> selectIssueAll() {
        SqlSession session = MyBatisUtil.getSession();
        MarketIssueMapper issueMapper = session.getMapper(MarketIssueMapper.class);
        MarketIssueExample marketIssueExample = new MarketIssueExample();
        List<MarketIssue> marketIssues = issueMapper.selectByExample(marketIssueExample);
        return marketIssues;
    }

    //使用模糊查询
    @Override
    public List<MarketIssue> selectIssueByIssueContent(String question) {
        SqlSession session = MyBatisUtil.getSession();
        MarketIssueMapper issueMapper = session.getMapper(MarketIssueMapper.class);
        MarketIssueExample marketIssueExample = new MarketIssueExample();
        marketIssueExample.or().andQuestionLike("%"+question.trim()+"%");
        List<MarketIssue> marketIssues = issueMapper.selectByExample(marketIssueExample);
        return marketIssues;
    }
}
